// pages/one/parse.js
const db = wx.cloud.database()
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    openid:'',
    question_id: '',
    choosed: '',
    question: null
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var question_id = options._id
    var choosed = options.choosed
    var openid = wx.getStorageSync('openid')
    if(!openid){
      wx.setStorageSync('returnUrl', '/pages/one/parse?_id='+question_id)
      wx.navigateTo({
        url: '../index/welcome',
      })
      return false
    }
    that.setData({
      openid,
      question_id,
      choosed
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.showLoading({
      title: '加载中',
    })
    //查询questionBank表数据
    var question_id = this.data.question_id
    db.collection('questionBank').doc(question_id).get({
      success: res => {
        this.setData({
          question: res.data
        })
        console.log(res.data)
        wx.hideLoading()
      },
      fail: err => {
        console.error('error', err)
      }
    })

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})